package com.RunAndHappy.q779178.server.service.impl;

import com.RunAndHappy.q779178.pojo.entity.User;
import com.RunAndHappy.q779178.server.mapper.UserMapper;
import com.RunAndHappy.q779178.server.service.UserService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.regex.Pattern;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public User loginService(String uname, String password) {
        User user = new User();
        user=userMapper.loginResult(uname,password);
        if(user!=null) {
            user.setPwd("");
            return user;
        }
        else
            return null;
    }

    @Override
    public User registService(User user) {
        if(userMapper.findExResult(user.getUsername())==null) {
            if (userMapper.registResult(user.getId(), user.getUsername(), user.getPwd(), user.getStatus(), user.getEmail(), user.getType(), user.getLocation(), user.getClasswork(), user.getPhone(), user.getClassid(), user.getAboutme()) >= 1) {
                return user;

            } else {
                return null;
            }
        }
        return null;
    }
}
